package com.rainng.coursesystem.manager.member;

import com.rainng.coursesystem.dao.EventDAO;
import com.rainng.coursesystem.dao.MemberEventDAO;
import com.rainng.coursesystem.manager.BaseManager;
import com.rainng.coursesystem.model.entity.MemberEventEntity;
import com.rainng.coursesystem.model.vo.response.table.MemberEventSelectedItemVO;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Component("member_EventManager")
public class EventManager extends BaseManager {
    private final MemberEventDAO memberEventDAO;
    private final EventDAO eventDAO;

    public EventManager(MemberEventDAO memberEventDAO, EventDAO eventDAO) {
        this.memberEventDAO = memberEventDAO;
        this.eventDAO = eventDAO;
    }

    public MemberEventEntity getMemberEventById(Integer memberEventId) {
        return memberEventDAO.get(memberEventId);
    }

    @Transactional
    public int deleteMemberEvent(MemberEventEntity memberEventEntity) {
        eventDAO.decreaseSelectedCount(memberEventEntity.getEventId());
        return memberEventDAO.delete(memberEventEntity.getId());
    }

    public List<MemberEventSelectedItemVO> listMemberEventSelected(Integer memberId) {
        return memberEventDAO.listMemberEventSelected(memberId);
    }
}
